/**
 * 字典管理配置文件
 */
import { h } from 'vue'
import { ElTag } from 'element-plus'

/**
 * 搜索条件配置
 */
export const searchConfig = [
  {
    field: 'word',
    label: '敏感词',
    component: 'Input',
    placeholder: '请输入敏感词',
    defaultValue: '',
  },
  {
    field: 'replaceWord',
    label: '替换词',
    component: 'Input',
    placeholder: '请输入替换词',
    defaultValue: '',
  },
  {
    field: 'wordType',
    label: '类型',
    component: 'Select',
    placeholder: '请选择类型',
    defaultValue: '',
    options: [
      { label: '禁用词', value: '1' },
      { label: '替换词', value: '2' },
      { label: '审核词', value: '3' },
    ],
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    placeholder: '请选择状态',
    defaultValue: '',
    options: [
      { label: '启用', value: '1' },
      { label: '禁用', value: '0' },
    ],
  },
]

/**
 * 表格列配置
 */
export const tableConfig = [
  {
    type: 'selection',
    width: 55,
    fixed: 'left',
  },
  {
    type: 'index',
    width: 55,
    label: '序号',
  },
  {
    prop: 'word',
    label: '敏感词',
    minWidth: 180,
  },
  {
    prop: 'replaceWord',
    label: '替换内容',
    minWidth: 180,
  },
  {
    prop: 'replaceWord',
    label: '类型',
    minWidth: 120,
    render: (row) =>
      h(
        ElTag,
        {
          type: row.wordType === '1' ? 'success' : row.wordType === '2' ? 'warning' : 'danger',
        },
        () => (row.wordType === '1' ? '禁用词' : row.wordType === '2' ? '替换词' : '审核词'),
      ),
  },
  {
    prop: 'status',
    label: '状态',
    minWidth: 120,
    render: (row) =>
      h(
        ElTag,
        {
          type: row.status === '1' ? 'success' : 'danger',
        },
        () => (row.status === '1' ? '启用' : '禁用'),
      ),
  },
  {
    prop: 'createOn',
    label: '创建时间',
    minWidth: 180,
    render: (row) => {
      if (!row.createOn) return '-'
      const date = new Date(row.createOn)
      return date
        .toLocaleString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit',
          second: '2-digit',
          hour12: false,
        })
        .replace(/\//g, '-')
    },
  },
  {
    prop: 'createUserName',
    label: '创建者',
    minWidth: 120,
    render: (row) => row.createUserName?.split(' ')[0] || '-',
  },
]
